/**
 *
 */
package com.sihai.ehr.web.action.ajax;

import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.biz.JobSpecificationProject;
import com.sihai.ehr.service.JobSpecificationService;
import com.sihai.ehr.web.action.EHRAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 * @author wxn
 * @since 2012-7-6 21:56
 */
public class ProjectAction extends EHRAction {
    @BeanInject
    private JobSpecificationService jobSpecificationService;
    
    private JobSpecificationProject project;

    @Action(value = "/ajax/project_get", results = {
            @Result(name = "success", type = "json", params = {"root", "project"})
    })
    public String getProjectDetail() {
        if(project != null && project.getId() != null && project.getId() > 0){
            project = jobSpecificationService.getProject(project.getId());
        }
        return SUCCESS;
    }
    @Action(value = "/ajax/project_remove", results = {
            @Result(name = "success", type = "json", params = {"root", "project"})
    })
    public String removeProject() {
        if(project != null && project.getId() != null && project.getId() > 0){
            jobSpecificationService.removeProject(project.getId());
        }
        return SUCCESS;
    }

    //修改工作项目
    @Action(value = "/ajax/project_edit", results = {
            @Result(name = "success", type = "json", params = {"root", "project"})
    })
    public String editProject() {
        if(project != null && project.getId() != null && project.getId() > 0){
            JobSpecificationProject p = jobSpecificationService.getProject(project.getId());
            p.setContent(project.getContent());
            p.setRateDay(project.getRateDay());
            p.setRateWeek(project.getRateWeek());
            p.setRateMonth(project.getRateMonth());
            p.setRateSeason(project.getRateSeason());
            p.setPercent(project.getPercent());
            p.setDegree(project.getDegree());

            jobSpecificationService.saveProject(p);

            project = p;
        }
        return SUCCESS;
    }


    public JobSpecificationProject getProject() {
        return project;
    }

    public void setProject(JobSpecificationProject project) {
        this.project = project;
    }

}